<!DOCTYPE html>
<html lang="zh-CN">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>智能对联生成器 - 仓颉语言实现</title>
    <style>
        body {
            font-family: 'Microsoft Yahei', sans-serif;
            margin: 0;
            padding: 0;
            background: #f5f5f5;
        }
        
        .container {
            max-width: 800px;
            margin: 0 auto;
            padding: 20px;
            background: white;
            margin-top: 50px;
            border-radius: 8px;
            box-shadow: 0 0 10px rgba(0, 0, 0, 0.1);
        }
        
        h1 {
            text-align: center;
            color: #333;
        }
        
        .form-group {
            margin-bottom: 20px;
        }
        
        label {
            display: block;
            margin-bottom: 8px;
            font-weight: bold;
        }
        
        input, select {
            width: 100%;
            padding: 10px;
            font-size: 16px;
            border: 1px solid #ddd;
            border-radius: 4px;
        }
        
        button {
            background: #4CAF50;
            color: white;
            padding: 12px 20px;
            border: none;
            border-radius: 4px;
            cursor: pointer;
            font-size: 16px;
            transition: background 0.3s;
        }
        
        button:hover {
            background: #45a049;
        }
        
        .result {
            margin-top: 30px;
            padding: 20px;
            background: #f8f8f8;
            border-left: 5px solid #4CAF50;
            display: none;
        }
        
        .couplet {
            font-size: 24px;
            margin: 10px 0;
            text-align: center;
        }
    </style>
</head>
<body>
    <div class="container">
        <h1>智能对联生成器</h1>
        <form id="coupletForm">
            <div class="form-group">
                <label for="first_line">请输入上联：</label>
                <input type="text" id="first_line" name="first_line" required>
            </div>
            <div class="form-group">
                <label for="style">选择风格：</label>
                <select id="style" name="style">
                    <option value="traditional">传统风格</option>
                    <option value="modern">现代风格</option>
                    <option value="humorous">幽默风格</option>
                </select>
            </div>
            <button type="submit">生成对联</button>
        </form>
        
        <div class="result" id="result">
            <div class="couplet" id="first"></div>
            <div class="couplet" id="second"></div>
        </div>
    </div>
    
    <script>
        document.getElementById('coupletForm').addEventListener('submit', function(e) {
            e.preventDefault();
            
            let first_line = document.getElementById('first_line').value;
            let style = document.getElementById('style').value;
            
            fetch(`/generate?first_line=${encodeURIComponent(first_line)}&style=${encodeURIComponent(style)}`)
                .then(response => response.json())
                .then(data => {
                    document.getElementById('first').textContent = data.first;
                    document.getElementById('second').textContent = data.second;
                    document.getElementById('result').style.display = 'block';
                })
                .catch(error => console.error('Error:', error));
        });
    </script>
</body>
</html>